package com.activemq.maintance;

import com.activemq.MqHelloWorld;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.boot.autoconfigure.jms.JmsProperties;

import javax.jms.*;

public class MsgSender {
    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(MqHelloWorld.URL);
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, JmsProperties.AcknowledgeMode.AUTO.getMode());
        Topic queue = session.createTopic(MsgSubscribe.TOPIC_NAME);
        MessageProducer producer = session.createProducer(queue);
        for (int i = 0; i < 6; i++) {
            TextMessage textMessage = new ActiveMQTextMessage();
            textMessage.setText("测试_" + i);
            producer.send(textMessage);
        }
        producer.close();
        session.close();
        connection.close();
    }
}
